import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yi_shop/components/coupon/book.dart';
import 'package:yi_shop/components/coupon/choice.dart';
import 'package:yi_shop/components/coupon/cloth.dart';
import 'package:yi_shop/components/coupon/computer.dart';
import 'package:yi_shop/components/coupon/food.dart';
import 'package:yi_shop/components/coupon/home.dart';
import 'package:yi_shop/components/coupon/household.dart';
import 'package:yi_shop/components/coupon/life.dart';
import 'package:yi_shop/components/coupon/maternal.dart';
import 'package:yi_shop/components/coupon/mobile.dart';
import 'package:yi_shop/components/coupon/outdoor.dart';
import 'package:yi_shop/components/coupon/personal.dart';
import 'package:yi_shop/components/coupon/store.dart';
import 'package:yi_shop/route/index.dart';
import 'package:yi_shop/ui/keep_alive.dart';
import 'package:yi_shop/utils/styles.dart';
import 'package:yi_shop/utils/tools.dart';

class CouponCenterController extends GetxController with GetTickerProviderStateMixin {
  late TabController controller;
  List<String> tabs = [
    '精选',
    '发现好店',
    '食品饮料',
    '手机数码',
    '家用电器',
    '母婴用品',
    '电脑办公',
    '服饰内衣',
    '个护化妆',
    '户外运动',
    '图书音像',
    '生活旅行',
    '家居家纺'
  ];

  @override
  void onInit() {
    controller = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    controller.dispose();
    super.onClose();
  }
}

class CouponCenterPage extends GetView<CouponCenterController> {
  const CouponCenterPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: ToolsUtils.builderLeading(),
        title: Text(
          '领券中心',
          style: StylesUtils.customTextStyle(
            fontSize: StylesUtils.fontSize18,
            fontWeight: FontWeight.w700,
          ),
        ),
        actions: [
          TextButton(
              onPressed: () {
                Get.toNamed(RoutePath.mineCouponList);
              },
              style: const ButtonStyle(alignment: Alignment.center),
              child: Text(
                '我的优惠券',
                style: StylesUtils.customTextStyle(),
              ))
        ],
        bottom: PreferredSize(
            preferredSize: const Size.fromHeight(40),
            child: Container(
              height: 40,
              color: Colors.white,
              alignment: Alignment.centerLeft,
              child: ToolsUtils.getClientTabBar(controller.tabs, controller.controller),
            )),
      ),
      body: TabBarView(
        controller: controller.controller,
        children: [
          KeepAliveWrapperTabView(
            child: const CouponChoiceView(),
            callback: () {
              Get.lazyPut(() => CouponChoiceController());
            },
          ),
          KeepAliveWrapperTabView(
              child: const GoodStoreView(),
              callback: () {
                Get.put(GoodStoreController());
              }),
          KeepAliveWrapperTabView(
              child: const FoodBeverageView(),
              callback: () {
                Get.put(FoodBeverageController());
              }),
          KeepAliveWrapperTabView(
              child: const MobileDigitalView(),
              callback: () {
                Get.put(MobileDigitalController());
              }),
          KeepAliveWrapperTabView(
              child: const HouseholdApplianceView(),
              callback: () {
                Get.put(HouseholdApplianceController());
              }),
          KeepAliveWrapperTabView(
              child: const MaternalProductView(),
              callback: () {
                Get.put(MaternalProductController());
              }),
          KeepAliveWrapperTabView(
              child: const ComputerOfficeView(),
              callback: () {
                Get.put(ComputerOfficeController());
              }),
          KeepAliveWrapperTabView(
              child: const ClothUnderwearView(),
              callback: () {
                Get.put(ClothUnderwearController());
              }),
          KeepAliveWrapperTabView(
              child: const PersonalMakeupView(),
              callback: () {
                Get.put(PersonalMakeupController());
              }),
          KeepAliveWrapperTabView(
              child: const OutdoorSportsView(),
              callback: () {
                Get.put(OutdoorSportsController());
              }),
          KeepAliveWrapperTabView(
              child: const BookAudioView(),
              callback: () {
                Get.put(BookAudioController());
              }),
          KeepAliveWrapperTabView(
              child: const LifeTravelView(),
              callback: () {
                Get.put(LifeTravelController());
              }),
          KeepAliveWrapperTabView(
              child: const HomeTextileView(),
              callback: () {
                Get.put(HomeTextileController());
              })
        ],
      ),
    );
  }
}
